<?php
class cartoon_controller_subscribe extends SnsController {
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->o = new cartoon_model_subscribe();
	}
	
	/**
	 * 添加订阅
	 *
	 */
	public function add_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$cartoon_id	=	_('cid');
		$this->_renderJson();
		if($rs = $this->o->add($cartoon_id,$uid)){
			if($rs == Error::ERROR_RECORD_EXISTS ){
				$this->ret = self::failure($rs);
			}
			else $this->ret = self::success();
		}else{
			$this->ret = self::failure(Error::ERROR_UNKNOWN );
		}
	}
	
	/**
	 * 添加订阅
	 *
	 */
	public function cancel_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$cartoon_id	=	_('ctid');
		$this->_renderJson();
		if($this->o->cancel($cartoon_id,$uid)){
			$this->ret = self::success();
		}else{
			$this->ret = self::failure("取消订阅失败！");
		}
	}
	
}